package com.xxx.video.commen.views;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import com.xxx.video.R;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.IosSingleChooseListAdapter;
import com.xxx.video.commen.utils.DimensionUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class IosSingleChoosePopupWindow extends BaseBottomPopupWindow implements BaseRecycleViewAdapter.OnItemClickListener<String> {

    @BindView(R.id.tv_popup_ios_single_choose_title)
    TextView tvPopupIosSingleChooseTitle;
    @BindView(R.id.rcv_popup_ios_single_choose_list)
    RecyclerView rcvPopupIosSingleChooseList;
    @BindView(R.id.tv_popup_ios_single_choose_cancel)
    TextView tvPopupIosSingleChooseCancel;

    public OnIosSingleChooseItemClickListener mOnIosSingleChooseItemClickListener;

    public IosSingleChoosePopupWindow(@NonNull Context context) {
        super(context);
    }

    @Override
    public int getContentLayout() {
        return R.layout.popup_ios_single_choose;
    }

    /**
     * set data
     *
     * @param title      title
     * @param cancelText cancel text
     * @param listData   list data
     */
    public void setData(String title, String cancelText, ArrayList<String> listData) {
        tvPopupIosSingleChooseTitle.setText(title);
        tvPopupIosSingleChooseCancel.setText(cancelText);
        if (listData.size()>5){
            this.setHeight(DimensionUtil.dpToPx(400));
        }
        IosSingleChooseListAdapter iosSingleChooseListAdapter = new IosSingleChooseListAdapter(context);
        rcvPopupIosSingleChooseList.setLayoutManager(new LinearLayoutManager(context));
        rcvPopupIosSingleChooseList.setAdapter(iosSingleChooseListAdapter);
        iosSingleChooseListAdapter.setData(listData);
        iosSingleChooseListAdapter.setOnItemClickListener(this);
    }

    @OnClick({R.id.tv_popup_ios_single_choose_title, R.id.tv_popup_ios_single_choose_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_popup_ios_single_choose_title:
                if (mOnIosSingleChooseItemClickListener != null) {
                    mOnIosSingleChooseItemClickListener.onIosSingleChooseItemClick("", -1, 2);
                }
                dismiss();
                break;
            case R.id.tv_popup_ios_single_choose_cancel:
                if (mOnIosSingleChooseItemClickListener != null) {
                    mOnIosSingleChooseItemClickListener.onIosSingleChooseItemClick("", -1, 1);
                }
                dismiss();
                break;
            default:
                break;
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initView(View view) {

    }

    @Override
    public void onItemClick(String s, int position, int type) {
        if (mOnIosSingleChooseItemClickListener != null) {
            mOnIosSingleChooseItemClickListener.onIosSingleChooseItemClick(s, position, type);
        }
        dismiss();
    }

    public interface OnIosSingleChooseItemClickListener {
        /**
         * item click call back
         *
         * @param string   item content
         * @param position position
         * @param type     event type
         */
        void onIosSingleChooseItemClick(String string, int position, int type);
    }

    /**
     * set item click
     *
     * @param onIosSingleChooseItemClickListener call back
     */
    public void setOnIosSingleChooseItemClickListener(OnIosSingleChooseItemClickListener onIosSingleChooseItemClickListener) {
        this.mOnIosSingleChooseItemClickListener = onIosSingleChooseItemClickListener;
    }
}
